	function aacalc(fio2,paco2,pao2){

//	var aagrad=0; made global
	var pAlv=0;
	var fierror=0;
	
//capture out of range error here

if (fio2>100){
 fierror=1;
 }

// A- a formula	
//PAO2 = ( FiO2 * (760 - 47)) - (PaCO2 / 0.8)
//  A-a gradient = PAO2 - PaO2

fio2=fio2/100;
pAlv=(fio2*(760-47))-(paco2/0.8);
aagrad= pAlv-pao2;

aagrad=Math.round(aagrad*100)/100;		


return {
			 aagrad:aagrad,
	     fierror:fierror
	};		 
}




function ref(){
// display reference
 return "Formula is: <br /> PAO2 = ( FiO2 * (760 - 47)) - (PaCO2 / 0.8)" + "<br />A-a gradient = PAO2 - PaO2" + "<br />The calculations assume 100% humidity at sea level and a respiratory quotient of 0.8" + "<BR /> A normal A-a gradient is less than 10 torr. The age (years)/4 + 4 is another conservative estimate of a normal gradient";
}